package com.ui.home.presenter;

import android.content.Context;

import com.base.BaseRefreshPresenter;
import com.bean.BaseBean;
import com.bean.SearchListBean;
import com.bean.WxArticleAuthorBean;
import com.net.ApiService;
import com.net.RetrofitServiceManager;
import com.net.RxResponseObserver;
import com.net.RxSchedulers;

import java.util.List;

public class WxArticleFragmentPresenter extends BaseRefreshPresenter<WxArticleFragmentContract.View> implements WxArticleFragmentContract.Presenter {
    private Context mContext;

    public WxArticleFragmentPresenter(Context context) {
        mContext = context;
    }

    @Override
    public void getArticle(int id, final int page) {
        RetrofitServiceManager.getInstance().create(ApiService.class).getWxArticleList(id,page)
                .compose(RxSchedulers.<BaseBean<SearchListBean>>normalSchedulers())
                .compose(mView.<BaseBean<SearchListBean>>bindToLife())
                .subscribe(new RxResponseObserver<BaseBean<SearchListBean>>() {
                    @Override
                    public void onSuccess(BaseBean<SearchListBean> baseBean) {
                        if (page == 0) {
                            mView.onGetArticle(baseBean.getData().getDatas());
                        }else {
                            mView.onLoadArticle(baseBean.getData().getDatas());
                        }
                    }
                });
    }

    @Override
    public void getAuthor() {
        RetrofitServiceManager.getInstance().create(ApiService.class).getWxAuthorList()
                .compose(RxSchedulers.<BaseBean<List<WxArticleAuthorBean>>>normalSchedulers())
                .compose(mView.<BaseBean<List<WxArticleAuthorBean>>>bindToLife())
                .subscribe(new RxResponseObserver<BaseBean<List<WxArticleAuthorBean>>>() {
                    @Override
                    public void onSuccess(BaseBean<List<WxArticleAuthorBean>> listBaseBean) {
                        mView.onGetAuthor(listBaseBean.getData());
                    }
                });
    }
}
